package com.xcdh.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xcdh.base.service.UserService;
import com.xcdh.commons.controller.BaseController;
import com.xcdh.domain.RequestPage;
import com.xcdh.domain.vo.PageVO;
import com.xcdh.domain.vo.R;
import com.xcdh.domain.entity.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController<UserDO , UserService>{

    @Autowired
    private UserService userService ;


    @GetMapping("/findUserByName")
    public R<UserDO> findUserByName(String username){
        return R.okData( userService.lambdaQuery()
                .eq(UserDO::getDelFlag , 0)
                .eq(UserDO::getUsername , username)
                .one()) ;
    }


    @Override
    public R<PageVO<UserDO>> listByPage(@RequestBody RequestPage<UserDO> page) {
        RequestPage<UserDO> result = userService.page(page);
        return R.page(result.getTotal(),result.getRecords());
    }
}
